
package laya.semi.process;

import java.util.*;

public class State
{
	public static final int START = 1;
	public static final int END = 2;
	public static final int ACTIVITY = 3;
	// public static final int INPUT = 4;
	public static final int FORK = 5;
	public static final int JOIN = 6;
	
	private String m_oStateId = null;
	private int m_nStateType = -1;
	private String m_oStateDescription = null;
	
	private List m_oInhibits = null;
	private List m_oActivities = null;
	private List m_oOutTransitions = null;
	
	public State(String oStateId)
	{
		m_oStateId = oStateId;
	}
	
	public State(String oStateId, int nType)
	{
		m_oStateId = oStateId;
		m_nStateType = nType;
	}
	
	public String getStateId()
	{
		return m_oStateId;
	}
	
	public void setStateType(int nType)
	{
		m_nStateType = nType;
	}
	
	public int getStateType()
	{
		return m_nStateType;
	}
	
	public void setStateDescription(String oValue)
	{
		m_oStateDescription = oValue;
	}
	
	public String getStateDescription()
	{
		return m_oStateDescription;
	}
	
	public void addCondition(Condition oCond)
		throws ProcessCompileException
	{
		if (END == m_nStateType)
		{
			throw new ProcessCompileException(1119, new Object[] {oCond, this});
		}
		
		if (null == m_oInhibits)
		{
			m_oInhibits = new Vector();
		}
		
		m_oInhibits.add(oCond);
	}
	
	public void addActivity(Activity oActivity)
	{
		if (null == m_oActivities)
		{
			m_oActivities = new Vector();
		}
		
		m_oActivities.add(oActivity);
	}
	
	public void addOutTransition(Transition oOut)
		throws ProcessCompileException
	{
		if (END == m_nStateType)
		{
			throw new ProcessCompileException(1104, new Object[] {oOut, this});
		}
		
		if (null == m_oOutTransitions)
		{
			m_oOutTransitions = new Vector();
		}
		
		m_oOutTransitions.add(oOut);
	}
	
	public List getInhibits()
	{
		return m_oInhibits;
	}
	
	public List getActivities()
	{
		return m_oActivities;
	}
	
	public List getOutTransitions()
	{
		return m_oOutTransitions;
	}
	
	public String getTypedName()
	{
		switch(m_nStateType)
		{
			case START: return "START";
			case END: return "END";
			case ACTIVITY: return "ACTIVITY";
			//case INPUT: return "INPUT";
			case FORK: return "FORK";
			case JOIN: return "JOIN";
		}
		return "UNKNOWN";
	}
	
	public String toString()
	{
		return m_oStateId + ": " + getTypedName();
	}
}
